﻿var viewstr = "<canvas id=\"viewer\"></canvas><canvas id=\"viewer1\" style=\"pointer-events:none;\"></canvas>";
var toolsbar = '<div  id="tabnew" class="toolsbar"><div class="tabcontent">\
        <div class="btn" data-animation="false" data-toggle="tooltip" data-placement="bottom" title="保存图片" >\
            <div  id="btnsaveimage" class="button btnsaveimage margin_15"></div>\
        </div>\
 <div class="line"></div>\
        <div class="btnjian" data-animation="false"  data-toggle="tooltip" data-placement="bottom" title="选择视角" >\
            <div id="btnSelectionPerspective"    class="button btnSelectionPerspective margin_15">\
                <div class="jiantou jiantou-sj"></div>\
            </div>\
        </div>\
        <div id="groupSelectionPerspective"  class="grouptools btn_c">\
            <div class="btn bgray"   data-animation="false"  data-toggle="tooltip" data-placement="left"  title="前视角">\
                <div id="btnqianshijiao" class="button btnqianshijiao margin_10"></div>\
            </div>\
            <div class="btn bgray"   data-animation="false"  data-toggle="tooltip" data-placement="left" title="后视角">\
                <div id="btnhoushijiao" class="button btnhoushijiao margin_10"></div>\
            </div>\
            <div class="btn bgray"   data-animation="false"  data-toggle="tooltip" data-placement="left" title="右视角">\
                <div id="btnyoushijiao" class="button btnyoushijiao margin_10"></div>\
            </div>\
            <div class="btn bgray"   data-animation="false"  data-toggle="tooltip" data-placement="left" title="左视角">\
                <div id="btnzuoshijiao" class="button btnzuoshijiao margin_10"></div>\
            </div>\
            <div class="btn bgray"   data-animation="false"  data-toggle="tooltip" data-placement="left" title="底视角">\
                <div id="btndishijiao" class="button btndishijiao margin_10"></div>\
            </div>\
            <div class="btn bgray"   data-animation="false"  data-toggle="tooltip" data-placement="left" title="顶视角">\
                <div id="btndingshijiao" class="button btndingshijiao margin_10"></div>\
            </div>\
        </div>\
<div class="line"></div>\
        <div class="btn" data-animation="false"  data-toggle="tooltip" data-placement="bottom"  title="初始视角">\
            <div id="btnClearScene" class="button btnchushijiao margin_15"></div>\
        </div>\
<div class="line"></div>\
        <div class="btnjian" data-animation="false"  data-toggle="tooltip" data-placement="bottom"  title="模型设置" >\
            <div id="btnModel" class="button btnxianshi margin_15">\
                <div class="jiantou jiantou-sj"></div>\
            </div>\
  </div>\
<div id="groupModel"  class="grouptools btn_c">\
            <div class="btn bgray"   data-animation="false"  data-toggle="tooltip" data-placement="left" title="显示模型" >\
                <div id="btnmodelshow"  class="button btnmodelshow margin_10"></div>\
            </div>\
            <div class="btn bgray"   data-animation="false"  data-toggle="tooltip" data-placement="left" title="隐藏模型">\
                <div id="btnmodelhide" class="button btnmodelhide  margin_10"></div>\
            </div>\
            <div class="btn bgray"  data-animation="false"  data-toggle="tooltip" data-placement="left" title="模型半透明">\
                <div id="btnmodeltouming"  class="button btnmodeltouming margin_10"></div>\
            </div>\
            <div class="btn bgray"  data-animation="false"  data-toggle="tooltip" data-placement="left" title="模型半透明恢复">\
                <div id="btnmodeltoumingreset"  class="button btnmodeltoumingreset margin_10"></div>\
            </div>\
        </div>\
<div class="line"></div>\
        <div class="btnjian"  data-animation="false"  data-toggle="tooltip" data-placement="bottom"  title="构件设置">\
            <div id="btnelement" class="button btngoujian margin_15">\
                <div class="jiantou jiantou-sj"></div>\
            </div>\
        </div>\
        <div id="groupelement" class="grouptools btn_c">\
            <div class="btn bgray"  data-animation="false"  data-toggle="tooltip" data-placement="left"  title="显示构件">\
                <div id="btnxianshiall" class="button btnxianshiall  margin_10"></div>\
            </div>\
            <div class="btn bgray" data-animation="false"  data-toggle="tooltip" data-placement="left"  title="隐藏构件">\
                <div id="btnyincangyuansu" class="button btnyincangyuansu  margin_10"></div>\
            </div>\
 <div class="btn bgray"  data-animation="false"  data-toggle="tooltip" data-placement="left"  title="构件半透明">\
                <div id="btnmoxingtouming"  class="button btnmoxingtouming  margin_10"></div>\
            </div>\
 <div class="btn bgray"  data-animation="false"  data-toggle="tooltip" data-placement="left"  title="构件半透明恢复">\
                <div id="btnyuansuxianshi" class="button btnyuansuxianshi  margin_10"></div>\
            </div>\
        </div>\
        <div class="line"></div>\
 <div class="btn" data-animation="false"  data-toggle="tooltip" data-placement="bottom"  title="视点管理">\
            <div id="btn_viewpoint" class="button viewpoint margin_15"></div>\
        </div>\
<div class="line"></div>\
<div class="btnjian tagjian" data-animation="false"  data-toggle="tooltip" data-placement="bottom" title="标签管理">\
            <div id="btntag" class="button tag margin_15">\
                <div class="jiantou jiantou-mj"></div>\
            </div>\
        </div>\
        <div id="grouptag" class="grouptools btn_c" >\
            <div class="btn bgray"  data-animation="false"  data-toggle="tooltip" data-placement="left" title="标签登记" style="width:100px;">\
                <div id="btntag_register" class="margin_15">标签登记</div>\
            </div>\
            <div class="btn bgray"  data-animation="false"  data-toggle="tooltip" data-placement="left"  title="历史标签" style="width:100px;">\
                <div id="btntag_Untreated"  class=" margin_15">历史标签</div>\
            </div>\
        </div>\
<div class="line"></div>\
        <div class="btn" data-animation="false"  data-toggle="tooltip" data-placement="bottom"  title="线框模式">\
            <div id="btnline" class="button btnline margin_15"></div>\
        </div>\
<div class="line"></div>\
        <div class="btn" data-animation="false"  data-toggle="tooltip" data-placement="bottom"  title="正常模式" >\
            <div id="btnlinecancel" class="button btnlinecancel margin_15"></div>\
        </div>\
        <div class="line"></div>\
        <div class="btnjian" data-animation="false"  data-toggle="tooltip" data-placement="bottom"  title="剖切" >\
            <div id="btnpaoqie" class="button btnpaoqie margin_15">\
                <div class="jiantou jiantou-pq"></div>\
            </div>\
        </div>\
        <div id="divpaoqie" class="setpqtools btn_c">\
<div class="title">剖切</div>\
                <span class="close">X</span>\
<ul class="lanren">\
	<li>X轴\
		<div class="scale_panel">\
			<div class="scale" id="barx">\
<input type="hidden" id="title-x" value="0">\
				<div id="x-axis"></div>\
				<span id="btnx"></span>\
			</div>\
		</div>\
	</li>\
<li>Y轴\
		<div class="scale_panel">\
			<div class="scale" id="bary">\
<input type="hidden" id="title-y" value="0">\
				<div id="y-axis"></div>\
				<span id="btny"></span>\
			</div>\
		</div>\
	</li>\
<li>Z轴\
		<div class="scale_panel">\
			<div class="scale" id="barz">\
<input type="hidden" id="title-z" value="0">\
				<div id="z-axis"></div>\
				<span id="btnz"></span>\
			</div>\
		</div>\
	</li>\
</ul></div>\
<div class="line"></div>\
<div class="btn"  id="jiegao" data-animation="false"  data-toggle="tooltip" data-placement="bottom"  title="属性">\
<div id="eledetail" class="margin_15 but_20"></div>\
</div>\
    <div class="line"></div>\
        <div class="btnjian"  data-animation="false"  data-toggle="tooltip" data-placement="bottom"  title="模式切换">\
            <div id="btnmode" class="button btnviewmode margin_15">\
                <div class="jiantou jiantou-sj"></div>\
            </div>\
        </div>\
        <div id="groupmode" class="grouptools btn_c">\
            <div class="btn bgray"  data-animation="false"  data-toggle="tooltip" data-placement="left"  title="预览模式">\
                <div id="btnviewmode" class="button btnviewmode  margin_10"></div>\
            </div>\
            <div class="btn bgray" data-animation="false"  data-toggle="tooltip" data-placement="left"  title="漫游模式">\
                <div id="btnposmode" class="button btnposmode  margin_10"></div>\
            </div>\
 <div class="btn bgray"  data-animation="false"  data-toggle="tooltip" data-placement="left"  title="管理模式">\
                <div id="btnguidmode"  class="button btnguidmode  margin_10"></div>\
            </div>\
        </div>\
        <div class="line"></div>\
        <div class="btnjian" data-animation="false"  data-toggle="tooltip" data-placement="bottom" title="设置">\
            <div id="btnshezhi" class="button btnshezhi margin_15">\
                <div class="jiantou jiantou-sz"></div>\
            </div>\
        </div>\
            <div id="divshezhi" class="settools btn_c">\
                <div class="title">设置</div>\
                <span class="close">X</span>\
                <ul>\
                    <li><span class="text">选中对象颜色</span><span id="sel_color" class="ck_color"></span></li>\
                    <li><span class="text">背景颜色</span><span id="bj_color" class="ck_color"></span></li>\
                    <li><span class="text">光照效果</span>\
                        <span id="Spanlight" class="t_checkbox">\
                            <i class="check_slider check_slider_hecked"></i><input type="checkbox" checked onclick="chkLight(this);" class="chk_3" id="ck_gz">\
                    </span></li>\
<li><span class="text">构件是否漫游</span>\
                        <span id="SpanisRoam" class="t_checkbox">\
                            <i class="check_slider check_slider_hecked"></i>\
                    </span></li>\
                    <li style="display:none"><span class="text">模型加载</span><div></div></li>\
                    <li><span class="text">着色方案</span><div></div></li>\
                </ul>\
            </div>\
    </div></div>'



var modelId = $("#hid_modelid").val();//获取模型ID
//container:容器id
function inittoolsbar(container) {
    var cameraPos = "";//当前相机位置
   // LoadPostionList();//加载视角列表
    var obj = document.getElementById(container);
    //$(obj).append(viewstr);
    $(obj).append(toolsbar);
    newpanelInit();
    DisplayTwoMenu("btnSelectionPerspective", "groupSelectionPerspective");
    DisplayTwoMenu("btnModel", "groupModel");
    DisplayTwoMenu("btnelement", "groupelement");
    //DisplayTwoMenu("btntag", "grouptag");
    DisplayTwoMenu("btnshezhi", "divshezhi");
    DisplayTwoMenu("btnmode", "groupmode");
    $(function () {  });
    //显示隐藏二级菜单
    function DisplayTwoMenu(id,groupid)
    {
        //$("#aaa").tooltip();
        $("#" + id + "").parent("div.btnjian").click(function () {
            closeRightWindow();//关闭所有右侧层
            var obj = this; 
            if ($("#" + groupid + "").hasClass("btn_c")) {
                canselbtncolor();
                $(obj).addClass("selbtn");
                $("#" + groupid + "").removeClass("btn_c").addClass("btn_s");
            } else {
                canselbtncolor();
                $(obj).removeClass("selbtn");
                $("#" + groupid + "").removeClass("btn_s").addClass("btn_c");
            }
        });
    }

    $("#btnpaoqie").parent("div.btnjian").click(function () {
        closeRightWindow();//关闭所有右侧层
        var obj = this;
        //var left = $(obj).css("left") + $(obj).offset();
        //$("#divpaoqie").css("left", left);
        if ($("#divpaoqie").hasClass("btn_c")) {
            canselbtncolor();
            $(obj).addClass("selbtn");
            $("#divpaoqie").removeClass("btn_c").addClass("btn_s");
            if (viewstr) {
                //if (bClip) {
                new scale('btnx', 'barx', 'x-axis', 'title-x');
                new scale('btny', 'bary', 'y-axis', 'title-y');
                new scale('btnz', 'barz', 'z-axis', 'title-z');
                //bClip = false;

                //} else {
                viewstr.unclip();
                //viewer.unclip();
                // bClip = true;
                //}
            }
        } else {
            canselbtncolor();
            $(obj).removeClass("selbtn");
            $("#divpaoqie").removeClass("btn_s").addClass("btn_c");
        }

    });

    $(".close").click(function () {
        //$("#divshezhi").removeClass("btn_s").addClass("btn_c");
        $(this).parent("div").removeClass("btn_s").addClass("btn_c");
        canselbtncolor();

    });
    //灯光按钮
    $("#divshezhi #Spanlight").click(function () {
        closeRightWindow();//关闭所有右侧层
        //切换选中状态
        if ($(this).parent("li").find("i.check_slider").hasClass("check_slider_hecked")) {
            $(this).parent("li").find("i.check_slider").removeClass("check_slider_hecked");
            SetLight(255, 255, 255, 1);
        } else {
            $(this).parent("li").find("i.check_slider").addClass("check_slider_hecked");
            SetLight(255, 255, 255, 1.5);
        }
    });


    //是否漫游按钮
    $("#divshezhi #SpanisRoam").click(function () {
        //切换选中状态
        if ($(this).parent("li").find("i.check_slider").hasClass("check_slider_hecked")) {
            $(this).parent("li").find("i.check_slider").removeClass("check_slider_hecked");
            isRoam = false;
        } else {
            isRoam = true;
            $(this).parent("li").find("i.check_slider").addClass("check_slider_hecked");
            
        }
    });

    //按钮与引擎方法绑定s
    $("#btnsaveimage").parent("div.btn").on("click", function (id) {
        selbtncolor(this);
        SaveImage();
    });

    //选择视角
    var viewpointAry = new Array("front", "back", "left", "right", "bottom","top");
    $("#groupSelectionPerspective>div").on("click", function () {
        SetViewPort(viewpointAry[$(this).index()]);
        selbtncolor(this);
        $("#btnSelectionPerspective").removeClass().addClass("" + $(this).children().attr("id") + " button margin_15");
        $("#btnSelectionPerspective").parent("div.btnjian").addClass("selbtn");
    });

    //模型
    $("#groupModel>div").on("click", function () {

        switch ($(this).index()) {
            case 0:
                $.each(Mids, function (i, item) {
                    SetModelVisible(item, true)//模型显示 
                })
                break;
            case 1:
                $.each(Mids, function (i, item) {
                    SetModelVisible(item, false)//模型隐藏
                })
                break;
            case 2:
                $.each(Mids, function (i, item) {
                    SetModelAlpha(item, 0.2)//模型半透明
                })
                break;
            case 3:
                $.each(Mids, function (i, item) {
                    SetModelAlpha(item, 1.0)//模型半透明恢复
                })
                break;

        }
        selbtncolor(this);
        $("#btnModel").removeClass().addClass("" + $(this).children().attr("id") + " button margin_15");
        $("#btnModel").parent("div.btnjian").addClass("selbtn");
        //$('#groupModel').hide();
    });

    //构件设置
    $("#groupelement>div").on("click", function () {
        var len = goujianListId.length;
        if (len == 0 && goujianid == 0)
        //if (goujianid == 0)
        {
            layer.msg('请先选择构件！', { icon: 0 });
            return false;
        }

        switch ($(this).index()) {
            case 0:
                for (var i = 0; i < len; i++) {
                    FnEleAttribute(goujianListId[i], 0)//批量显示构件
                }
                FnEleAttribute(goujianid, 0)
                break;
            case 1:
                for (var i = 0; i < len; i++) {
                    FnEleAttribute(goujianListId[i], 1)//隐藏构件
                }
                FnEleAttribute(goujianid, 1)

                break;
            case 2:
                for (var i = 0; i < len; i++) {
                    FnEleAttribute(goujianListId[i], 2)//构件半透明
                }
                FnEleAttribute(goujianid, 2)

                break;
            case 3:
                for (var i = 0; i < len; i++) {
                    FnEleAttribute(goujianListId[i], 3)//构件半透明恢复
                }

                FnEleAttribute(goujianid, 3)
                break;

        }
        selbtncolor(this);
        $("#btnelement").removeClass().addClass("" + $(this).children().attr("id") + " button margin_15");
        $("#btnelement").parent("div.btnjian").addClass("selbtn");
    })


    //构件状态属性设置
    function FnEleAttribute(goujianid, type)
    {
        switch (type) {
            case 0: SetActorVisible(goujianid, true)//显示构件
                break;
            case 1: SetActorVisible(goujianid, false)//隐藏构件
                break;
            case 2: SetActorAlpha(goujianid, 0.2)//构件半透明
                break;
            case 3: SetActorAlpha(goujianid, 1)//构件半透明恢复
                break;

        }
    }

    //标签登记
    $("#btntag_register").parent("div.btn").on("click", function () {
        SetClickMode(3);
        clickMode = 3;
        closeRightWindow();//关闭所有右侧层
        IsAddTag = true;//开启标签登记状态
        $("body").css("cursor", "crosshair");//设置鼠标样式
    });

    //$(window).hover(
    //  function () {
    //      ('#tagtip').show();
    //  }
    // );
    
    //模式切换
    $("#groupmode>div").on("click", function () {
        switch ($(this).index()) {
            case 0: SetClickMode(0);//查看模式
                clickMode = 0;
                break;
            case 1: SetClickMode(1);//漫游模式
                clickMode = 1;
                break;
            case 2: SetClickMode(2);//管理模式
                clickMode = 2;
                break;
        }
        selbtncolor(this);
        $("#btnmode").removeClass().addClass("" + $(this).children().attr("id") + " button margin_15");
        $("#btnmode").parent("div.btnjian").addClass("selbtn");
    })

    $(window).mousemove(function (e) {
        var top = e.pageY + 5;
        var left = e.pageX + 5;
        $('#tagtip').css({
            'top': top + 'px',
            'left': left + 'px'
        });
    });

    $(window).mouseout(function () {
        $('#tagtip').hide();
    });



    //显示隐藏标签管理二级菜单
    $("#btntag_register,#btntag_Untreated").on("click", function () {
        $("#grouptag").hide();
    })

    //标签管理
    $(".tagjian").on("click", function () {
        closeRightWindow();//关闭所有右侧层
        if (!$(this).hasClass("selbtn")) {
            canselbtncolor();
            $(this).addClass("selbtn");
            $("#grouptag").show();
        } else {
            $(this).removeClass("selbtn");
            $("#grouptag").hide();
        }
    })

    //历史标签
    $("#btntag_Untreated").parent("div.btn").on("click", function () {
        
        closeRightWindow();//关闭所有右侧层
        showRightWindow("histroytagdiv");//关闭所有右侧层
        //$("#model_tagList").hide();
        //$('.right-detection-list').hide();
        //$('.right-detection-list').hide();
        $('#tagIModelListForm .right-detection-list').show();
        $("#model_tagUntreatedList").show();
        $.mask_element('#tagdivloading', 3000);
        LoadTagSiteList();//加载所有标签定位
        LoadTagList();
    });

    //新增图标
    $('#add-icon-select-modal').on('click', function () {   
        index = layer.open({
            type: 1,
            skin: 'layui-layer-lan', //样式类名
            anim: 2,
            title: ['新增图标', true],
            shadeClose: true, //开启遮罩关闭
            area: ['450px', '300px'], //宽高
            //offset: ['100px', '40%'],
            content: $('#icon-select-modal-main'),
            success: function (layero, index) {
            layer.iframeAuto(index);

        },
        });
    });



    //关闭新增图标层
    $('#tagIcoModelForm #close_add_modal').on('click', function () {
        layer.close(index);
    })




    //标签图标列表
    $('#icon-input').click(function () {
        $('#icon-select-div').toggle();
    });
    $('#icon-select-div p').click(function () {
        $('#icon-select-div p').children('i').hide();
        $(this).children('i').show();
        $('#icon-select-div').hide();
        var html_seletc = $(this).html();
        var html_text = $(this).text();
        $('.icon-input-div>p').html(html_seletc);
        $('.icon-input-div>input').val(html_text);
    });


    //关闭历史标签
    $('#tagIModelListForm .list-title-close').on('click', function () {
        canselbtncolor();
        closeRightWindow();//关闭所有右侧层
    });


    //关闭标签登记
    $(".right-detection-list .cancel-but").click(function () {
        canselbtncolor();
        closeRightWindow();//关闭所有右侧层
        $("#btnreset").click();
        //$("#model_tagList").hide();
       //$(".right-detection-list").hide();
    })

   

    //自定义视点
    $("#btn_viewpoint").parent("div.btn").on("click", function () {
       
        if (!$(this).hasClass("selbtn")) {
            closeRightWindow();//关闭所有右侧层
            showRightWindow("viewpointdiv");//显示当前右侧标签
            canselbtncolor();
            $(this).addClass("selbtn");
            // $('.right-detection-list').hide();
            $("#model_viewpoint").show();
            //$('.viewpoint .right-detection-list').show();
            LoadPostionList();//加载视角列表
        } else {
            closeRightWindow();//关闭所有右侧层
            $(this).removeClass("selbtn");
        }
        $.mask_element('.viewpoint-list-main', 3000);
    })

    //保存当前视点
    $(".right-detection-list #viewpoint-but").on("click", function () {
        var posVaule = GetCamera();//获取视角坐标值
        var posThumbImg = GetImage();//获取视角缩略图base64值
        $("#posName").val("");
        $("#posDescribe").val("");
        $("#hid_posThumbImg").val(posThumbImg);
        $("#hid_posVaule").val(posVaule);
        $("#posThumbImg").attr("src", posThumbImg);
    })

    //关闭自定义视点
    $('.viewpoint .list-title-close').on('click', function () {
        canselbtncolor();
        closeRightWindow();//关闭所有右侧层
       // $('.viewpoint .right-detection-list').hide();
    });

    //保存视点遮罩

    $('#viewpoint-but').on('click', function () {
        index = layer.open({
            type: 1,
            skin: 'layui-layer-lan', //样式类名
            anim: 2,
            title: ['保存视点', true],
            shadeClose: true, //开启遮罩关闭
            area: ['400px', '450px'], //宽高
            //offset: ['100px', '40%'],
            success: function (layero, index) {
                layer.iframeAuto(index);

            },
            content: $('#viewpoint-modal-main')
        });
    });
    $('#viewpoint-modal-main #close_add_modal').on('click', function () {
        layer.close(index);
    })

    //线框模式
    $("#btnline").parent("div.btn").on("click", function () {
        RemoveTagList();
        closeRightWindow();
        canselbtncolor();
        $(this).addClass("selbtn");
        var c = "#999999";
        //指定默认背景色
        SetBackGroundColor(parseInt(c.substr(1, 2), 16), parseInt(c.substr(3, 2), 16), parseInt(c.substr(5, 2), 16), 255);
        //selbtncolor(obj);
        $.each(modelidList.split(","), function (i, item) {
            SetModelWireFrame(item);
        })
    })

    //正常模式
    $("#btnlinecancel").parent("div.btn").on("click", function () {
        RemoveTagList();
        closeRightWindow();
        canselbtncolor();
        $(this).addClass("selbtn");
        var c = "#ffffff";
        SetBackGroundColor(parseInt(c.substr(1, 2), 16), parseInt(c.substr(3, 2), 16), parseInt(c.substr(5, 2), 16), 255);
        $.each(modelidList.split(","), function (i, item) {
            SetModelNomal(item);
        })
    })

  
    $("#jiegao").on('click', function () {
        SetClickMode(2);
        clickMode = 2;
        closeRightWindow();//关闭所有右侧层
        var obj = $("#myTabContent #" + type);
        obj.addClass(" active in");//显示选项卡
        if (!$(this).hasClass("selbtn")) {
            if (goujianid != 0) {
                mdldetailshow(goujianid, type);//显示属性
            } else {
                obj.html("<ul><li colspan=\"2\">请选择构件！</li></ul>");
            }
            canselbtncolor();
            $(this).addClass("selbtn");
            showRightWindow("SandBoxLisInfo");//显示当前层
            //$('.SandBoxLisInfo').toggle();
            //event.stopPropagation();
        } else {
            $(this).removeClass("selbtn");
            closeRightWindow();//关闭所有右侧层
        }
    })

    //构件漫游

    //$(window).bind("dblclick", function () { //双击事件 
    //    if (isRoam) {
    //        ZoomTo(clickpos);
    //    }
    //})



    //注册菜单选择事件
    function delegateMenuEvent(obj, parentName, removeClassName, addClassName) {
        canselbtncolor();
        selbtncolor(obj);
        $("#" + parentName).removeClass(removeClassName).addClass(addClassName);
        $("#" + parentName).parent("div.btnjian").addClass("selbtn");
    }


    //初始视角
    $("#btnClearScene").parent("div.btn").on("click", function () {
        closeRightWindow();
        canselbtncolor();
        $(this).addClass("selbtn");
        //ClearScene();
        SetViewPort("front");
        ResetAllActor();
    });
   
    //按钮与引擎方法绑定e

}
//添加标签
function addtag(path, name) {
    AddAnchor(goujianid, path, name);
}



  var type = "properties";//属性选项卡标识
    //切换构件列表选项卡
  $(".box-default #myTab li").on("click", function () {
      $("#myTabContent>div").html("");//清空所有tabpane
        type = $(this).data("type");
        var obj = $("#myTabContent #" + type);
        if (goujianid != 0) {
            mdldetailshow(goujianid, type);//显示属性
        } else {
            obj.addClass(" active in");//显示选项卡
            obj.html("<ul><li colspan=\"2\">请选择构件！</li></ul>");
        }
    })

//移除所有标签
  function RemoveTagList() {
      $("#tagIModelListForm .right-detection-list-main .line-div").each(function (i, item) {
          var obj = $(item).find("span");
          var icoName = obj.data("iconame");
          console.log(icoName);
          RemoveAnchor(icoName);//移除标签
      })
  }

function setdensity() {
    if ($("#txtweight").val() != null) {
        var aa = $("#txtweight").val();
        var regtest = isNum(aa);
        if (regtest) {
            SetThickness((aa * 1) / 1000);//设置密度
        }
    } else {
        alert("请输入材质的密度");
    }
}
function selbtncolor(obj) {
    canselbtncolor();
    $("#tabnew div").removeClass("selbtn");
    $(obj).addClass("selbtn");
}

//关闭右侧所有层
function closeRightWindow() {
    $(".rightdiv").hide();//隐藏右侧弹层
    ResetMouseStyle();//还原鼠标样式
    RemoveTagList();//清空标签列表
    $("#grouptag").hide();//隐藏标签管理二级菜单
}

//显示右侧弹层
function showRightWindow(classname)
{
    $("." + classname).show();
}

//还原鼠标样式
function ResetMouseStyle() {
    IsAddTag = false;//关闭标签登记标识
    $("body").css("cursor", "default");//还原鼠标样式
    RemoveAnchor("defaultico");//移除默认标签
}

function selparentbtncolor(obj) {
    canselbtncolor();
    $("#tabnew div").removeClass("selbtn");
    $(obj).addClass("selbtn");
}
function setposition(obj, nowclass, selclass) {
    //$(obj).background.position.x = x;
    //$(obj).background.position.y = y;
    //$(obj).attr("background-position", xy);
    $(obj).removeClass(nowclass).addClass(selclass);
}
function canselbtncolor() {
    $("#tabnew div").removeClass("selbtn");
    $(".grouptools").removeClass("btn_s").addClass("btn_c");
    $(".settools").removeClass("btn_s").addClass("btn_c");
    $(".setpqtools").removeClass("btn_s").addClass("btn_c");
    $("#btnxianshi").removeClass("btnxianshiall").removeClass("btnxianshiyuansu").removeClass("btnyincangyuansu").addClass("btnxianshi");
    //$("#btnmianji").removeClass("btnpingmianji").removeClass("btnbiaomianji").addClass("btnmianji");
    //stopPointMeasure();
    //stopSurfaceMeasure();
    //stopPlaneMeasure();
    //stopVolumeMeasure();
    //stopAngleMeasure();
    //stopWeightMeasure();
    //setBlowState(false);

}
function newpanelInit() {
    var colors = ['red', 'green', 'blue', 'yellow'],
        index = 0;
    var getColor = function () {
        (index >= colors.length) && (index = 0);
        return colors[index++];
    };


    $("#sel_color").colpick({
        color: 'ff0000',
        layout: 'hex',
        submit: true,
        onSubmit: function (color, color2,e,el) {
            pickColor = '#' + color2;
            selObjectColor = pickColor;
            $(el).colpickHide();
            //viewer.defineStyle(0, [parseInt(pickColor.substr(1, 2), 16), parseInt(pickColor.substr(3, 2), 16), parseInt(pickColor.substr(5, 2), 16), 255]);
            //viewer.defineStyle(0, [255,0,0,255]);  //red

            //for (var i = 0; i < clickIds.length; i++) {
            //    viewer.setStyle(0, [clickIds[i]]);
            //}
            //viewer.setStyle(0, [selectId]);
            var selids = $("#selectids").val();
            var arrstr = selids.split('#');
            for (var i = 0; i < arrstr.length; i++) {
                SetActorColor(arrstr[i], [parseInt(pickColor.substr(1, 2), 16), parseInt(pickColor.substr(3, 2), 16), parseInt(pickColor.substr(5, 2), 16), 255]);
            }
            
        }
    });
    $("#bj_color").colpick({
        layout: 'hex',
        submit: true,
        onSubmit: function (color, color2,e,el) {
            pickColor = '#' + color2;
            //if (viewer) viewer.background = [parseInt(pickColor.substr(1, 2), 16), parseInt(pickColor.substr(3, 2), 16), parseInt(pickColor.substr(5, 2), 16), 255];
            //return 0;
            SetBackGroundColor(parseInt(pickColor.substr(1, 2), 16), parseInt(pickColor.substr(3, 2), 16), parseInt(pickColor.substr(5, 2), 16), 255);
            $(el).colpickHide();
        }, onHide: function () {
        }
    });
}
var scale = function (btn, bar, zhou, title) {
    this.btn = document.getElementById(btn);
    this.bar = document.getElementById(bar);
    this.title = document.getElementById(title);
    this.step = document.getElementById(zhou);
    this.initscale();
};
scale.prototype = {
    initscale: function () {
        var f = this, g = document, b = window, m = Math;
        f.btn.onmousedown = function (e) {
            var x = (e || b.event).clientX;
            var l = this.offsetLeft;
            var max = f.bar.offsetWidth - this.offsetWidth;
            g.onmousemove = function (e) {
                var thisX = (e || b.event).clientX;
                var to = m.min(max, m.max(-2, l + (thisX - x)));
                f.btn.style.left = to + 'px';
                f.ondrag(m.round(m.max(0, to / max) * 100), to);
                b.getSelection ? b.getSelection().removeAllRanges() : g.selection.empty();
            };
            g.onmouseup = new Function('this.onmousemove=null');
        };
    },
    ondrag: function (pos, x) {
        this.step.style.width = Math.max(0, x) + 'px';
        this.title.value = pos;
        console.log(($("#title-x").val()));
        PlateClip('x-min', ($("#title-x").val()) * 1 / 100);
        //PlateClip('x-max', 1);

        PlateClip('y-min', ($("#title-y").val()) * 1 / 100);
        //PlateClip('y-max', 1);

        PlateClip('z-min', ($("#title-z").val()) * 1 / 100);
        //PlateClip('z-max', 1);
    }
}
function isNum(a) {
    var reg = new RegExp("^[0-9]*$");
    return reg.test(a);

}


//显示增加标签
function FnShowAddTag() {
    if (clickpos == "") {
        layer.msg('请先选择构件！', { icon: 0 });
        return false;
    }
    showRightWindow("addtagdiv");//显示当前右侧标签
    $("#model_tagList").show();//加载页面
    $("#componenPosition").val(clickpos);

    //$(".addtagdiv").on("mouseover",function(event){
    //     ('#tagtip').hide();
    // })
    LoadTagTypeList();
}
//加载类型列表
function LoadTagTypeList() {
    var obj = $("#tagType");
    $(obj).html("<option value=''>请选择标签类型</option>");
    $.get("/Ajax/GetTagTypeList", function (data) {
        $.each(data, function (i, item) {
            $(obj).append("<option value='" + item.id + "'>" + item.tagTypeName + "</option>");
        })
    })
}